//
//  CLReadViewBGController.m
//  CLBrowser
//
//  Created by 梁慧聪 on 2022/8/15.
//

#import "CLReadViewBGController.h"

@interface CLReadViewBGController ()

@end

@implementation CLReadViewBGController

- (void)viewDidLoad {
    [super viewDidLoad];
    // imageView
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.backgroundColor = [CLReadConfigure sharedInstance].bgColor;
    [self.view addSubview:imageView];
    imageView.frame = self.view.bounds;
    
    // 显示背面
//        funcOne()
    [self funcTwo];
    
    // 清空视图
    _targetView = nil;
}

// MARK: 方式一

/// 方式一

- (void)funcOne {
    
    // 展示图片
    if (_targetView != nil) {
        
        self.imageView.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
        
        self.imageView.image = [_targetView snapshot];
    }
}

// MARK: 方式二

/// 方式二
- (void)funcTwo {
    
    // 展示图片
    if (_targetView != nil) {
        
        CGRect rect = _targetView.frame;
        
        UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0);
        
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGAffineTransform transform = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0, rect.size.width, 0.0);
        
        CGContextConcatCTM(context, transform);
        [_targetView.layer renderInContext:UIGraphicsGetCurrentContext()];
        
        self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
    }
}
@end
